package com.skycong.hello77.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import com.skycong.hello77.R;
import java.util.List;

/**
 * Created by Kiki on 2018/4/27.
 */

public class InflateTestAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<String> dataList;
    private Context context;
    public InflateTestAdapter(Context context, List<String> data){
        this.mInflater = LayoutInflater.from(context);
        this.dataList = data;
    }
    @Override
    public int getCount() {
        Log.i("msg","大小"+dataList.size());
        return dataList.size();

    }

    @Override
    public Object getItem(int position) {
        Log.i("msg","位置"+dataList.get(position));
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.i("msg","视图");
        ViewHolder holder = null;
          if(convertView == null){
             // convertView = mInflater.inflate(R.layout.infalte_listview_item,parent,true);
              convertView = View.inflate(parent.getContext(), R.layout.infalte_listview_item,null);

              holder = new ViewHolder();
              holder.mBtn = (Button) convertView.findViewById(R.id.id_btn);
                  convertView.setTag(holder);
          }else{
              holder = (ViewHolder) convertView.getTag();
          }
        holder.mBtn.setText(dataList.get(position));
          return convertView;


    }
    private class ViewHolder{
        public Button mBtn;
    }
}
